﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace P8_Drawing;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    private SolidColorBrush brush = new SolidColorBrush(Colors.Black);
    private bool isDrawing = false;
    private Point lastPoint;

    private void ColorPicker_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color?> e)
    {
        if (e.NewValue.HasValue)
        {
            brush = new SolidColorBrush(e.NewValue.Value);
        }
    }

    private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
    {
        isDrawing = true;
        lastPoint = e.GetPosition(canvas);
    }

    private void Canvas_MouseMove(object sender, MouseEventArgs e)
    {
        if (isDrawing && e.LeftButton == MouseButtonState.Pressed)
        {
            Point currentPoint = e.GetPosition(canvas);

            Line line = new Line
            {
                Stroke = brush,
                StrokeThickness = brushSizeSlider.Value,
                X1 = lastPoint.X,
                Y1 = lastPoint.Y,
                X2 = currentPoint.X,
                Y2 = currentPoint.Y
            };

            canvas.Children.Add(line);
            lastPoint = currentPoint;
        }
    }

}